package org.scut.smartgeometry.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * Created by Administrator on 13-6-27.
 */
public class StylePickerDialog extends Dialog {

    private OnStyleChangedListener styleChangedListener;
    private static String[] stylesStr = new String[]{"Stroke", "Fill"};

    public StylePickerDialog(Context context, OnStyleChangedListener l) {
        super(context);
        this.styleChangedListener = l;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle("Pick a Style");

        RadioGroup group = new RadioGroup(getContext());
        for (int i = 0; i<stylesStr.length; i++){
            RadioButton btn = new RadioButton(getContext());
            btn.setText(stylesStr[i]);
            btn.setTextSize(20);
            btn.setTextColor(Color.BLACK);
            group.addView(btn, i);
        }

        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                int id = radioGroup.getCheckedRadioButtonId();
                RadioButton btn = (RadioButton) radioGroup.findViewById(id);
                String styleStr = btn.getText().toString();

                if(styleStr.equalsIgnoreCase("Stroke")){
                    styleChangedListener.styleChanged(Paint.Style.STROKE);
                }else if(styleStr.equalsIgnoreCase("Fill")){
                    styleChangedListener.styleChanged(Paint.Style.FILL);
                }

                dismiss();
            }
        });

        setContentView(group);
    }


    public interface OnStyleChangedListener{
        void styleChanged(Paint.Style style);
    }


}
